<?php
class M_Faqs extends Apps_Db_Table_Abstract {
    protected $_name = 'faqs';

    const STATUS_ACTIVE   = 1;
    const STATUS_INACTIVE = 0;

    // get One Faqs
    public function getOneFaqs($faqId) {
        $q = $this->_db
                  ->select()
                  ->from('faqs', null)
                  ->where('id = ?', $faqId)
                  ->where('status = ?', self::STATUS_ACTIVE)
                  ->columns(array(
                  			'id' 			=> 'faqs.id',
                  			'description' 	=> 'faqs.description'
                  		));

        if($this->getLang() == 'en') {
            $q->columns(array('question'    => 'faqs.en_question',
                              'answer'    	=> 'faqs.en_answer'));
        } else $q->columns(array('question' => 'faqs.question',
                                 'answer' 	=> 'faqs.answer'));

        return $q;
    }

	// get all Faqs
    public function getFaqsByCategoryId($categoryId) {
    	$q = $this->_db
			    	->select()
			    	->from('faqs', null)
			    	->join('faqs_category', 'faqs_category.id = faqs.faqs_category_id', null)
			    	->where('faqs.status = ?', self::STATUS_ACTIVE)
			    	->where('faqs_category.id =? ', $categoryId)
			    	->columns(array(
			    			'id' 			=> 'faqs.id',
			    			'description' 	=> 'faqs.description',
			    			'category_title'=> 'faqs_category.title'
    	));

    	if($this->getLang() == 'en') {
    		$q->columns(array('question'    => 'faqs.en_question',
    						  'answer'    	=> 'faqs.en_answer'));
    	} else $q->columns(array('question' => 'faqs.question',
    							'answer' 	=> 'faqs.answer'));

    	return $q;
    }

}